using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Configuration;
using System.Web.UI;
using System.Web.UI.WebControls;


public partial class JobSeekers_resumedetails: System.Web.UI.Page
{
    string connectionString = "";
    protected void Page_Load(object sender, EventArgs e)
    {
        connectionString =
             WebConfigurationManager.ConnectionStrings[
               "Database2000"].ConnectionString;
        if (Session.Contents["jsuserid"] == null)
        {
            Response.Redirect("login.aspx");
        }
        if (Session["ResumeID"] == null)
        {
            Response.Redirect("resume.aspx");
        }
        ResumeID.Value = Session["ResumeID"].ToString();
        
        if (!IsPostBack)
        {
            ControlHelper controlHelper = new ControlHelper("");
            controlHelper.CommandText =
            "select * from tblJobCategories; " +
            "Select * from tblJobIndustries;" +
            "select * from tblProvinces";
            controlHelper.InitProperties();
            controlHelper.FillDataTableToDropDownList(
            ddlCategory, ddlIndustry, ddlProvince,
            "JobCategoryName", "JobIndustryName",
            "ProvinceName", "JobCategoryID",
            "JobIndustryID", "ProvinceID", "", "", "");
            ResumeStatus.Value = Convert.ToString(Session["ResumeStatus"]);
            
            EditResume(Session["ResumeID"].ToString());
        }    
    }
    void EditResume(string resumeID)
    {
        if (resumeID != "" && resumeID != null )
        {
            SqlServerProvider cls = new SqlServerProvider(connectionString);
            cls.CommandText = "select D.* from " +
            " tblJSResumes,tblJSResumeDetails D where UserID='" 
            + Session["jsuserid"] +
             "' and D.ResumeID='" + resumeID
             + "'";
            DataTable dataTable =
            cls.GetDataTable( );
            if(dataTable.Rows.Count>0)
            {
                txtPosition.Text=dataTable.Rows[0][1].ToString();                
                ddlCategory.SelectedValue=dataTable.Rows[0][2].ToString();
                ddlIndustry.SelectedValue=dataTable.Rows[0][3].ToString();
                ddlProvince.SelectedValue=dataTable.Rows[0][4].ToString();
                txtCity.Text=dataTable.Rows[0][5].ToString();
                txtStartSalary.Text=dataTable.Rows[0][6].ToString();
                txtEndSalary.Text =dataTable.Rows[0][7].ToString();
                ddlCurrency.SelectedValue=dataTable.Rows[0][8].ToString();
                chkNegotive.Checked=((dataTable.Rows[0][9].ToString()=="True")?true:false);
                chkRalocate.Checked=((dataTable.Rows[0][10].ToString()=="True")?true:false);
                rblType.SelectedValue=dataTable.Rows[0][11].ToString();
                rblLevel.SelectedValue=dataTable.Rows[0][12].ToString();
                ddlStatus.SelectedValue = dataTable.Rows[0][13].ToString();
                txtDescription.Text = dataTable.Rows[0][14].ToString();
                
            }
        }
    }
    protected void btnNext_Click(object sender, EventArgs e)
    {

        if(SaveResumeDetails() == "")            
        {
            if (Session["ResumeStatus"].ToString() == "Update")
            {
                
                Response.Redirect("resumes.aspx");
            }
            else
            {
                
                Session.Remove("ResumeStatus");
                Response.Redirect("other.aspx");
            }
        }
    }
    protected void Button2_Click(object sender, EventArgs e)
    {
        if(SaveResumeDetails() == "")            
        {
            
            Session.Remove("ResumeStatus");
            Response.Redirect("thankyou.aspx");
        }
    }
    string  SaveResumeDetails()
    {
        string errorMsg = "";
        SqlServerProvider cls = new SqlServerProvider(connectionString);
        if(!cls.AddNewUpdateResume(
        (ResumeStatus.Value == "New"),
        ResumeID.Value,
        txtPosition.Text,
        ddlCategory.SelectedValue,
        ddlIndustry.SelectedValue,
        ddlProvince.SelectedValue,
        txtCity.Text, txtStartSalary.Text,
        txtEndSalary.Text,
        ddlCurrency.SelectedValue,
        chkNegotive.Checked,
        chkRalocate.Checked,
        rblType.SelectedValue,
        rblLevel.SelectedValue,
        ddlStatus.SelectedValue,
        txtDescription.Text)) 
            errorMsg = cls.ErrorMessage;
        return errorMsg;
    }
}
